package top.songxs.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.common.result.ResultCodeEnum;
import top.songxs.gmall.product.dto.SkuInfoDto;
import top.songxs.gmall.product.entity.SkuInfo;
import top.songxs.gmall.product.service.SkuInfoService;

@RestController
@RequestMapping("admin/product")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    @GetMapping("/list/{page}/{limit}")
    public Result<Page<SkuInfo>> findSkuInfoPage(@PathVariable("page") Integer pageNum, @PathVariable("limit") Integer pageSize) {
        Page<SkuInfo> pages = skuInfoService.findSkuInfo(pageNum, pageSize);
        return Result.build(pages, ResultCodeEnum.SUCCESS);
    }
    //http://api.gmall.com/admin/product/saveSkuInfo
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoDto skuInfoDto) {
        skuInfoService.saveSkuInfo(skuInfoDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //http://api.gmall.com/admin/product/onSale/{skuId}
    //skuId：skuId
    //Get
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId) {
        skuInfoService.ongSale(skuId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    //http://api.gmall.com/admin/product/cancelSale/{skuId}
    //skuId：skuId
    //Get
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId) {
        skuInfoService.cancelSale(skuId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
